unit testRead;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  fpcunit,
  //testutils,
  testregistry,
  common;//our session BO/BO list is on common unit

type

  { TTestRead }

  TTestRead= class(TTestCase)
  private
    obj:TPerson;
    objlist:TPersonList;
  protected
    procedure SetUp; override; 
    procedure TearDown; override;
  published
    Procedure TestReadObject;
    Procedure TestReadObjectByCriteria;

    Procedure TestReadObjectListByCriteria;
  end;
implementation
uses
  hadecriteria;
procedure TTestRead.SetUp; 
begin
  obj:=Tperson.Create;
  objList:=TPersonList.Create;
end; 

procedure TTestRead.TearDown; 
begin
  FreeAndNil(objlist);
  FreeAndNil(obj);
end;

procedure TTestRead.TestReadObject;
begin
  obj.OID.IntegerOID:=71;//set OID first
  session.Read(obj);
  self.AssertEquals('Fajar',obj.First_Name);
end;

procedure TTestRead.TestReadObjectByCriteria;
var
  fexpr: THadeCriteria;
begin
  fexpr:=THadeCriteria.Create(obj);
  fexpr.Equal('age',21);
  session.Read(obj,fexpr);
  AssertEquals('Fajar',obj.First_Name);
end;

procedure TTestRead.TestReadObjectListByCriteria;
var
  fexpr: THadeCriteria;
begin
  fexpr:=THadeCriteria.Create(objlist);

  fexpr.between('oid',156,160);
  session.Read(objlist,fexpr);
  AssertEquals(5,objlist.count);
  AssertEquals(156,objlist.items[0].OID.IntegerOID);
end;

initialization
  RegisterTest(TTestRead); 
end.

